<template>

        <el-card>
            <el-form :inline="true" ref="form" :model="password" label-width="80px">


                <el-form-item label="原密码:">
                    <el-input v-model="password.oldpassword"></el-input>
                </el-form-item>


                <el-form-item label="新密码:">
                    <el-input v-model="password.newpassword"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" @click="onSubmit">修改</el-button>
                    <el-button @click="reset">重置</el-button>
                </el-form-item>
            </el-form>

        </el-card>

</template>

<script>
    export default {
        name: "password",
        data(){
            return{
                password:{
                    oldpassword:'',
                    newpassword:''
                }
            }
        },
        methods:{
         async   onSubmit(){
                let username = this.$store.state.username
                if (username && this.password.oldpassword && this. password.newpassword){
                    console.log(username);
                    let userInfo={
                        name:username,
                        pwd:this.password
                    }
                   let {data:res }=await this.$http.put('/account',userInfo)
                    console.log(res);
                    if( res.meta.status!= 200)  return  this.$message.error(res.meta.msg)
                    this.$message.success(res.meta.msg)
                    this. password. oldpassword=this. password. newpassword=''


                }
            },
            reset(){
                this. password. oldpassword=this. password. newpassword=''
            }
        }
    }
</script>

<style scoped>

</style>
